package com.ihd.ihardware.view.tzc.health.view;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.ihd.ihardware.R;
import com.ihd.ihardware.common.adapter.FragmentAdapter;
import com.ihd.ihardware.databinding.ActivityDetailBinding;
import com.ihd.ihardware.pojo.NormRes;
import com.ihd.ihardware.pojo.Test_rp;
import com.ihd.ihardware.view.tzc.health.viewmodel.ReportViewModel;

import java.util.ArrayList;
import java.util.List;

import cn.wowjoy.commonlibrary.base.BaseActivity;

public class DataDetailActivity extends BaseActivity<ActivityDetailBinding, ReportViewModel> {

    private List<NormRes.DataBean> rd;
    private Test_rp index;
    private List<Test_rp> raw;
    private List<Test_rp> finalData;
    private FragmentAdapter mFragmentAdapteradapter;

    @Override
    protected void init(Bundle savedInstanceState) {
        mImmersionBar.statusBarDarkFont(true).init();
        binding.mtitlebar.setTitle("数据指标详情");
        binding.mtitlebar.setTitleColor(getResources().getColor(R.color.C_32353B));
        binding.mtitlebar.setLeftBack(this);
        binding.mtitlebar.setLeftImageResource(R.drawable.ic_back);

        raw = (List<Test_rp>) getIntent().getSerializableExtra("raw");
        rd = (List<NormRes.DataBean>) getIntent().getSerializableExtra("data");
        index = (Test_rp) getIntent().getSerializableExtra("index");

        List<Fragment> fragments = new ArrayList<>();
        finalData = new ArrayList<>();
        for (int k = 0; k < raw.size(); k++) {
            for (int j = 0; j < rd.size(); j++) {
                if (rd.get(j).getType() == raw.get(k).getType()) {
                    finalData.add(raw.get(k));
                    fragments.add(DataDetailFragment.newInstance(rd.get(j), raw.get(k)));
                }
            }
        }
        mFragmentAdapteradapter = new FragmentAdapter(getSupportFragmentManager(), fragments, finalData);
        binding.viewpager.setAdapter(mFragmentAdapteradapter);
        binding.viewpager.setOffscreenPageLimit(rd.size());
        binding.tabs.setupWithViewPager(binding.viewpager);

        for (int i = 0; i < finalData.size(); i++) {
            if (index.getType() == finalData.get(i).getType()) {
                binding.viewpager.setCurrentItem(i);
                break;
            }
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_detail;
    }

    @Override
    protected Class getViewModelClass() {
        return ReportViewModel.class;
    }

}
